﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace getPixelInformation
{
    class greyLevel
    {
        private List<element> l;
        private int n;
        private int[] temp;

        public greyLevel()
        {
            this.n = 0;
            this.l = new List<element>();
            this.temp = new int[this.n];
        }

        public greyLevel(int n)
        {
            this.l = new List<element>();
            this.n = n;
            this.temp = new int[this.n];       
            for (int i = 0; i < this.n; i++)
            {   
                element e = new element(0, 0);
                this.l.Add(e);
            }
        }

        public greyLevel(greyLevel g)
        {
            this.n = g.n;
            this.l = new List<element>();
            this.temp= new int[this.n];
            for (int j = 0; j < this.n; j++)
            {
                this.l[j] = g.l[j];
                this.temp[j] = g.temp[j];
            }
        }

        public void setCountGreyLevel(int i, int temp)
        {
            //this.l[i].addCount();
            this.temp[i]++;
        }

        public double getElementRate(int i)
        {
            return this.l[i].getRate();
        }

        public int getCountFromValue(int i)
        {
            return this.l[i].getCount();
        }

        public int sumPixels()
        {
            int sum = 0;
            for (int i = 0; i < this.n; i++)
            {
                sum = sum + this.temp[i];
            }
            return sum;
        }

        public void updateRateElement()
        {
            int sum = this.sumPixels();
            double rate;
            for (int i = 0; i < this.n; i++)
            {
                rate = (double)temp[i] / sum;
                this.l[i].setRate(rate);
            }
        }

        public void updateRateElementFormer()
        {
            int sum = this.sumPixels();
            double rate;
            for (int i = 0; i < this.n; i++)
            {
                rate = (double)this.l[i].getCount() / sum;
                this.l[i].setRate(rate);
            }
        }

        public void addNewCountGreyLevel(int i, int value)
        {
            this.l[i].addCount(value);
        }

        public int getValueCountTemp(int i)
        {
            return this.temp[i];
        }

    }
}
